package com.lzy.huijinjiazu.mvp.ui.adapter;

import android.support.v7.widget.CardView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.jess.arms.utils.ArmsUtils;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.model.entity.Finance;
import com.lzy.huijinjiazu.mvp.ui.activity.FinanceDetailActivity;
import com.lzy.huijinjiazu.mvp.ui.widget.CircleProgress;
import com.lzy.huijinjiazu.mvp.ui.widget.TagGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by long on 2018/1/10.
 */

public class FinanceAdapter extends BaseQuickAdapter<Finance, BaseViewHolder> {


    public FinanceAdapter() {
        super(R.layout.item_finance);
    }

    @Override
    protected void convert(BaseViewHolder helper, Finance item) {
        FrameLayout fLayout = (FrameLayout) helper.itemView;
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        if (helper.getLayoutPosition() == 0) {
            fLayout.setPadding(ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 5));
        } else if (helper.getLayoutPosition() == getItemCount()) {
            fLayout.setPadding(ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 5), ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 10));
        } else {
            fLayout.setPadding(ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 5), ArmsUtils.dip2px(mContext, 10), ArmsUtils.dip2px(mContext, 5));
        }

        ImageView ivAd = helper.getView(R.id.iv_ad);
        FrameLayout flAd = helper.getView(R.id.fl_ad);
        LinearLayout llNoComplete = helper.getView(R.id.ll_no_complete);
        CircleProgress viewPro = helper.getView(R.id.view_pro);
        TagGroup tgList = helper.getView(R.id.tg_list);
        llNoComplete.setVisibility(item.isComplete() ? View.VISIBLE : View.GONE);
        flAd.setVisibility(item.isComplete() ? View.GONE : View.VISIBLE);
        productionView(tgList, null);

        helper.itemView.setOnClickListener(view -> {
            FinanceDetailActivity.start(mContext, "景林稳健一号");
        });
    }

    private void productionView(TagGroup tgList, List<String> data) {
        if (tgList.getChildCount() > 0) {
            return;
        }
        data = new ArrayList<>();
        data.add("腾邦");
        data.add("腾邦");
        tgList.setList(data);
        for (int i = 0; i < tgList.getChildCount(); i++) {
            RoundTextView tvView = (RoundTextView) tgList.getChildAt(i);
            tvView.setText(data.get(i));
            tvView.getDelegate().setStrokeColor(0xFF999999);
            tvView.setTextColor(0xFF999999);
            tvView.getDelegate().setBackgroundColor(0x00000000);
            tvView.setTextSize(12);
            tvView.setPadding(15, 5, 15, 5);
        }
    }
}
